import request from '@/utils/request'
import { defineStore } from 'pinia'
import { IApiRes, bannerItem, goodItem , hotItem, Brand , HomeProduct} from '@/types/data'
export default defineStore('home', {
  state: () => ({
    bannerList: [] as bannerItem[],
    newGoodList: [] as goodItem[],
    hotGoodList: [] as hotItem[],
    brandList: [] as Brand[],
    productList: [] as HomeProduct[]
  }),
  actions: {
    //轮播图
    async getBannerList() {
      const res = await request.get<IApiRes<bannerItem[]>>('/home/banner')
        //   console.log(res.data.result)
          this.bannerList = res.data.result
    },
    //新鲜好物
    async getNewList() {
      const res = await request.get<IApiRes<goodItem[]>>('/home/new')
      // console.log(res.data.result)
      this.newGoodList = res.data.result
    },
    //人气
    async getHotList() {
      const res = await request.get<IApiRes<hotItem[]>>('/home/hot')
      // console.log(res)
      this.hotGoodList = res.data.result
    },
    async getBrand() {
      const res = await request.get<IApiRes<Brand[]>>('/home/brand')
      console.log(res.data.result);
      this.brandList = res.data.result
    },
    async getProduct() {
      const res = await request.get<IApiRes<HomeProduct[]>>('/home/goods')
      // console.log(res.data.result);
      this.productList = res.data.result
    }
  },
})
